const setSessionItem = (key: string, value: any) =>{
    try {
        const serializedValue = JSON.stringify(value);
        sessionStorage.setItem(key, serializedValue);
    } catch (error) {
        console.error("设置会话存储项时出错:", error);
    }
}

const getSessionItem = (key: string) => {
    try {
        const serializedValue = sessionStorage.getItem(key);
        if (serializedValue === null) {
        return null;
        }
        return JSON.parse(serializedValue);
    } catch (error) {
        console.error("获取会话存储项时出错:", error);
        return null;
    }
}

const removeSessionItem = (key: string) => {
    try {
        sessionStorage.removeItem(key);
    } catch (error) {
        console.error("删除会话存储项时出错:", error);
    }
}

const clearSessionAll = () => {
    try {
        sessionStorage.clear();
    } catch (error) {
        console.error("清空会话存储时出错:", error);
    }
}

export {
    setSessionItem,
    getSessionItem,
    removeSessionItem,
    clearSessionAll
}